<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>员工权限管理</title>
<%@ include file="../../common/Style.jsp"%>
<script>
$(document).ready(function(){
	parent.$.messager.progress('close'); 
});
var functionPrefix = "function";
function saveOrUpdateFunction(){
	var roleID = $("#roleId").val();
	if (roleID == 0){
		$.messager.alert('错误', '请先选择角色', 'error');
		$("#roleId").focus();
	} else {
		var value = $("#function90").is(':checked');
		if (!value || (value && confirm("你赋予了此角色<权限管理>，请确认!")) ){
		    var params=$("#userInforForm").serialize();  
		    $.post("userJSON!saveUserFunctions",params, updateFunctionBackProcess,"json");	   
		}
	}
    
}

function updateFunctionBackProcess(data){
	var user = data.isSuccess;
	if (user == true)
		$.messager.alert('结果', '更新成功', 'info');
	else
		$.messager.alert('错误', '更新成功', 'error');
}

function submitRole(){
	
	var roleID = $("#roleId").val();

	if (roleID == 0){
		clearAllData();
	} else {
	    var params=$("#userInforForm").serialize();  

	    $.post("userJSON!getRole",params, getUserBackProcess,"json");	
	}
}
function getUserBackProcess(data){
    var role = data.role;
    if (role != ""){
    	$("#roleId").val(role.role_id);
   
    	
    	var functions = role.roleFunction_Set;	
    	clearAllFunctionData();
    	
	    if (functions.length != 0)
		    for (var i = 0; i < functions.length; i++){
		        var fun = functions[i];
		        $("#"+functionPrefix+fun).prop("checked",true);
		    }
    }else {
    	$.messager.alert('错误', '获取信息发生错误!', 'error');
    	
    }
}
function clearAllData(){
	clearAllFunctionData();
	$("#name").val("");
	$("#jobTitle").val("");
	$("#department").val("");
}

function clearAllFunctionData(){
	$("input[name='functionalities']").prop("checked",false);
}



//if the manageAll is enable, the manage mine should be enabled as well
function changeFunction13(){
	var value = $("#function13").is(':checked');
	
	if (value){
		$("#function14").prop("checked",true);
	}	
}

//if the manage mine is disabled, the manage all should be disabled as well
function changeFunction14(){
	var value = $("#function14").is(':checked');
	
	if (!value){
		$("#function13").prop("checked",false);
	}	
}
</script>

</head>
<body>

	<s:form id="userInforForm" name="formBean.userInfor" action="" method="POST"  theme="simple">
		<table width="90%" align="center" class="OuterTable">
			<tr>
				<td>

 <table width="100%" border="0">
    <tr class="PBAOuterTableTitale">
       <td colspan="6">用户角色权限分配</td>
    </tr>

    <tr class="InnerTableContent">
      <td><strong>现有角色：</strong> </td>
      <td><s:select name="formBean.userInfor.roleType" headerKey="0"  headerValue="-------"   cssClass="easyui-combobox"
			id="roleId"  list="uiBean.roles" listKey="chainRoleTypeId" listValue="chainRoleTypeName"  data-options="onChange:function(current, old){submitRole();}"/> </td>
      <td width="162">&nbsp;</td>
      <td width="192"></td>
      <td width="155">&nbsp;</td>
      <td width="344"></td>
    </tr>
 
    <tr class="InnerTableContent">
      <td height="4" colspan="6"><hr width="100%" color="#FFCC00"/></td>
    </tr>
    <tr class="InnerTableContent">
      <td width="144" height="19"><strong>条形码管理权限</strong></td>
      <td width="191">基础资料管理1:
      <input type="checkbox" name="functionalities" id="function1" value="1"/></td>
      <td>新建条形码2:<input type="checkbox" name="functionalities" id="function2" value="2"/></td>
      <td>查询条形码3:<input type="checkbox" name="functionalities" id="function3" value="3"/></td>
      <td>修改条形码4:<input type="checkbox" name="functionalities" id="function4" value="4"/></td>
      <td>同步检查条码5:<input type="checkbox" name="functionalities" id="function5" value="5"/></td>
    </tr>
    <tr class="InnerTableContent">
      <td height="4" colspan="6"><hr width="100%" color="#FFCC00"/></td>
    </tr>
    <tr class="InnerTableContent">
      <td height="19"><strong>人力资源管理权限</strong></td>
      <td>员工信息管理10:<input type="checkbox" name="functionalities" id="function10" value="10"/></td>
      <td>绩效考核配置11:<input type="checkbox" name="functionalities" id="function11" value="11"/></td>
      <td>创建员工考核管理12:<input type="checkbox" name="functionalities" id="function12" value="12"/></td>
      <td>管理自己员工考核14:<input type="checkbox" name="functionalities" id="function14" value="14" onclick="changeFunction14();"/></td>
      <td>管理所有员工考核13:<input type="checkbox" name="functionalities" id="function13" value="13" onclick="changeFunction13();"/></td>
    </tr>
    <tr class="InnerTableContent">
      <td height="4">&nbsp;</td>
      <td height="4">查看员工考核月报表15:
      <input type="checkbox" name="functionalities" id="function15" value="15"/></td>
      <td height="4">&nbsp;</td>
      <td height="4">&nbsp;</td>
      <td height="4">&nbsp;</td>
      <td height="4">&nbsp;</td>
    </tr>
    <tr class="InnerTableContent">
      <td height="4" colspan="6"><hr width="100%" color="#FFCC00"/></td>
    </tr>
    <tr class="InnerTableContent">
      <td height="19"><strong>单据管理权限</strong></td>
      <td>PDA单据录入24:<input type="checkbox" name="functionalities" id="function24" value="24"/></td>
      <td>仓库单据录入21:<input type="checkbox" name="functionalities" id="function21" value="21"/></td>
      <td>搜索单据22:<input type="checkbox" name="functionalities" id="function22" value="22"/></td>
      <td>会计修改单据23:<input type="checkbox" name="functionalities" id="function23" value="23"/></td>
      <td>会计审核单据28:<input type="checkbox" name="functionalities" id="function28" value="28"/></td>
    </tr>
    <tr class="InnerTableContent">
      <td height="19"></td>
      <td>删除单据26:<input type="checkbox" name="functionalities" id="function26" value="26"/></td>
      <td>导入精算27:<input type="checkbox" name="functionalities" id="function27" value="27"/></td>
      <td>客户信息管理18:<input type="checkbox" name="functionalities" id="function18" value="18"/></td>
      <td>客户财务管理16:<input type="checkbox" name="functionalities" id="function16" value="16"/></td>
      <td>客户流水17:<input type="checkbox" name="functionalities" id="function17" value="17"/></td>
    </tr>
    <tr class="InnerTableContent">
      <td height="19"></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>    
    <tr class="InnerTableContent">
      <td height="4" colspan="6"><hr width="100%" color="#FFCC00"/></td>
    </tr>
    <tr class="InnerTableContent">
      <td height="19"><strong>连锁管理权限</strong></td>
      <td>销售报表31:<input type="checkbox" name="functionalities" id="function31" value="31"/></td>
      <td>连锁店关联93:<input type="checkbox" name="functionalities" id="function93" value="93"/></td>
      <td>连锁店起初库存94:<input type="checkbox" name="functionalities" id="function94" value="94"/></td>
      <td></td>
      <td></td>
    </tr>
    <tr class="InnerTableContent">
      <td height="4" colspan="6"><hr width="100%" color="#FFCC00"/></td>
    </tr>   
    <tr class="InnerTableContent">
      <td height="19"><strong>供应商管理</strong></td>
      <td>供应商信息管理41:<input type="checkbox" name="functionalities" id="function41" value="41"/></td>
      <td>供应商财务管理42:<input type="checkbox" name="functionalities" id="function42" value="42"/></td>
      <td>供应商采购管理43:<input type="checkbox" name="functionalities" id="function44" value="44"/></td>
      <td>总部库存管理44:<input type="checkbox" name="functionalities" id="function43" value="43"/></td>
      <td></td>
    </tr>   
       <tr class="InnerTableContent">
      <td height="4" colspan="6"><hr width="100%" color="#FFCC00"/></td>
    </tr>   
    <tr class="InnerTableContent">
      <td height="19"><strong>报表管理</strong></td>
      <td>总部报表管理45:<input type="checkbox" name="functionalities" id="function45" value="45"/></td>
      <td>成本查看46:<input type="checkbox" name="functionalities" id="function46" value="46"/></td>

      <td></td>
    </tr>   
    <tr class="InnerTableContent">
      <td height="4" colspan="6"><hr width="100%" color="#FFCC00"/></td>
    </tr>        
    <tr class="InnerTableContent">
      <td height="19"><strong>管理员权限</strong></td>
      <td>总部用户权限管理90:<input type="checkbox" name="functionalities" id="function90" value="90"/></td>
      <td>连锁系统管理员91:<input type="checkbox" name="functionalities" id="function91" value="91"/></td>
      <td>连锁经理92:<input type="checkbox" name="functionalities" id="function92" value="92"/></td>
      <td>品牌价格调整32:<input type="checkbox" name="functionalities" id="function32" value="32"/></td>
      <td></td>
    </tr>
    <tr class="InnerTableContent">
      <td height="4" colspan="6"><hr width="100%" color="#FFCC00"/></td>
    </tr>        
    <tr class="InnerTableContent">
      <td height="19"><strong>财务权限</strong></td>
      <td>总部费用管理19:<input type="checkbox" name="functionalities" id="function19" value="19"/></td>

      <td></td>
    </tr>
        <tr class="InnerTableContent">
      <td height="4" colspan="6"><hr width="100%" color="#FFCC00"/></td>
    </tr>    
    <tr class="InnerTableContent">
      <td height="19"><strong>客户管理</strong></td>
      <td>客户标签编辑管理20:<input type="checkbox" name="functionalities" id="function20" value="20"/></td>

      <td>客户标签查询管理25:<input type="checkbox" name="functionalities" id="function25" value="25"/></td>
    </tr>
    <tr class="InnerTableContent">
      <td height="4" colspan="6"><hr width="100%" color="#FFCC00"/></td>
    </tr> 
    <tr class="InnerTableContent">
      <td height="30">&nbsp;</td>
      <td><a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="saveOrUpdateFunction();">更新</a></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr class="InnerTableContent">
      <td height="2" colspan="6"></td>
    </tr>
  </table>
  </td></tr>
 </table>
</s:form>

</body>
</html>